<!DOCTYPE html>
<html>
<head>
    {include file="_Fragment/meta" /}
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="user-table" lay-filter="user-table"></table>
    </div>
</div>

<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        导入
    </button>
</script>
<script type="text/html" id="table-status">
    {{#if (d.status == '1') { }}
    <span style="color: #1E9FFF;">成功</span>
    {{# }else if(d.status == '2'){ }}
    <span style="color: #FF5722;">失败</span>
    {{# } }}
</script>
<script type="text/html" id="create-time">
    {{layui.util.toDateString(d.add_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['table', 'form', 'jquery','common'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;

        let cols = [
            [{
                type: 'checkbox'
            },
                {
                    title: 'ID',
                    field: 'id',
                    align: 'center'
                },
                {
                    title: '导入日期',
                    field: 'add_time',
                    align: 'center',
                    templet: '#create-time'
                },
                {
                    title: '操作员',
                    field: 'admin_user',
                    align: 'center',
                },
                {
                    title: 'Flex',
                    field: 'flex',
                    align: 'center'
                },
                {
                    title: '导入文档',
                    field: 'title',
                    align: 'center'
                },
                {
                    title: '处理状态',
                    field: 'status',
                    align: 'center',
                    templet:'#table-status',
                },
                {
                    title: '导入成功',
                    field: 'ok',
                    align: 'center'
                },
                {
                    title: '导入失败',
                    field: 'fail',
                    align: 'center'
                },
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/Tna/load',
            page: {layout:['count', 'prev', 'page', 'next', 'skip']},
            limit: 10,
            cols: cols,
            //skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });
        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
                ,page: {
                    curr: 1, //重新从第 1 页开始
                    layout:['count', 'prev', 'page', 'next', 'skip']
                }
                ,limit: 10,
            })
            return false;
        });


        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            }
        });



        window.add = function() {
            layer.open({
                type: 2,
                title: '导入',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/Tna/import'
            });
        }

        window.refresh = function(param) {
            table.reload('user-table');
        }
    })
</script>
</body>
</html>
